<?php 
/** Load header
*/
$this->load->view('header', $template) ;
?>
<link rel="stylesheet" href="<?php echo base_url() ?>assets/css/user.css">
<!-- ---------------------------------------------------------- -->

	
	<section class="nav">
		<div class="wrapper">
			<div class="nav">
				<nav>
					<ul>
						<li class="profile selected">Thông tin cá nhân</li>
						<li class="uploaded">Tài liệu đã tải lên</li>
						<li class="reading">Tài liệu đang đọc</li>
						<li class="tags">Ghi chú, gợi ý</li>
					</ul>
				</nav>						
			</div>
		</div>
	</section>

	<section>
		<div class="wrapper content">

			<div class="profile">
				<h2>
					Thông tin cá nhân					
				</h2>
				<p>
					<span>Tên đăng nhập: </span>
					<span style="color: #ff9900; font-weight: 700;"><?php echo $user['username']; ?></span>
				</p>
				<p>
					<span>Họ tên: </span>
					<span><?php echo $user['fullname']; ?></span>
				</p>
				<p>
					<span>Ngày sinh: </span>
					<span><?php echo $user['dob']; ?></span>
				</p>
				<p>
					<span>Giới tính: </span>
					<span><?php echo $user['gender']; ?></span>
				</p>
				<p>
					<span>Email: </span>
					<span><?php echo $user['email']; ?></span>
				</p>
				<p>
					<span>Nghề nghiệp: </span>
					<span><?php echo $user['job']; ?></span>
				</p>
				<p>
					<span>Quan tâm: </span>
					<span><?php echo $user['interestedin']; ?></span>
				</p>

				<p>&nbsp;</p>	

				<p>
					<span></span>
					<span><a href="user/show_profile" title="">CHỈNH SỬA</a></span>
				</p>
			</div>

			<div class="uploaded">
				<a href="user/upload" class="zone">
					TẢI TÀI LIỆU &nbsp; <i class="fa fa-upload"></i>
				</a>
				<h2>Tài liệu đã tải lên</h2>

				<?php foreach($uploaded as $book) { ?>
				<figure class="book">
					<p class="title"><?php echo $book['name_document'] ?></p>
					<p class="author">Tác giả: &nbsp; <?php echo $book['author'] ?></p>
					<p class="category"><i class="fa fa-briefcase"></i> &nbsp; 
						<?php echo $book['name_cat'] ?></p>
					<!-- <p class="read"><i class="fa fa-eye"></i> &nbsp; 123</p> -->
					<p class="more">
						<a href="book/show_info_book/<?php echo $book['id_document'] ?>" title="">Sửa thông tin</a> &nbsp; | &nbsp; 
						<a href="book/info/<?php echo $book['id_document'] ?>" title="">
							Đọc tài liệu
						</a> &nbsp; | &nbsp; 
						<a href="book/delete_book/<?php echo $book['id_document'] ?>" title=""
							onclick="return confirm('Bạn có chắc muôn xóa tài liệu này chứ?')">Xóa tài liệu</a>
					</p>
					<div class="cover"><img src="<?php echo $book['cover']; ?>" alt=""></div>
				</figure>
				<?php } ?>
			</div>

			<div class="reading">
				<h2>Tài liệu đang đọc</h2>

				<?php foreach($reading as $book) { ?>
				<figure class="book">
					<p class="title"><?php echo $book['name_document'] ?></p>
					<p class="author">Tác giả: &nbsp; <?php echo $book['author'] ?></p>
					<p class="category"><i class="fa fa-briefcase"></i> &nbsp; 
						<?php echo $book['name_cat'] ?> &nbsp; | &nbsp; 
						<i class="fa fa-upload"></i> &nbsp; <?php echo $book['username']; ?>
					<p class="chapter"><i class="fa fa-bookmark"></i> &nbsp; <?php echo $book['name_chap']; ?></p>
					<!-- <p class="read"><i class="fa fa-eye"></i> &nbsp; 123</p> -->
					<p class="more">
						<a href="book/read/<?php echo $book['id_document'].'/'.$book['id_chap'] ?>" title="">
							Đọc tiếp
						</a> &nbsp; | &nbsp; 
						<a onclick="removeReading('<?php echo $book["id_document"]; ?>')">
							Bỏ theo dõi</a>
					</p>
					<div class="cover"><img src="<?php echo $book['cover']; ?>" alt=""></div>
				</figure>
				<?php } ?>
				
			</div>

			<div class="tags">
				<h2>Ghi chú, gợi ý</h2>

				<?php foreach($tags as $node) { ?>
				<figure class="book">
					<p class="title"><?php echo $node['name_document'] ?></p>
					<p class="author">Tác giả: &nbsp; <?php echo $node['author'] ?></p>
					<p class="category"><i class="fa fa-briefcase"></i> &nbsp; 
						<?php echo $node['name_cat'] ?> &nbsp; | &nbsp; 
						<i class="fa fa-bookmark"></i> &nbsp; 
						<?php echo $node['name_chap']; ?> 
					</p>
					<?php if($node['location'] != 'null') { ?>
					<!-- <p class="local">
						<i class="fa fa-crosshairs"></i> <?php // echo $node['type_location'].' '.$node['name_location']; ?>
					</p> -->
					<?php } ?>
					<p class="text-zone"><span style="color: #ff9900">
						Gợi ý:</span> &nbsp; 
						<?php echo $node['name_tags'] ?>
					</p>
					<p class="more">
						<a href="book/read/<?php echo $node['id_document'].'/'.$node['id_chap'].'?tag='.$node['id_tags'] ?>" title="">
							Xem gợi ý
						</a> &nbsp; | &nbsp; 
						<a href="book/remove_tag/<?php echo $node['id_tags'] ?>">
							Hủy bỏ ghi chú</a>
					</p>
					<div class="cover"><img src="<?php echo $node['cover']; ?>" alt=""></div>
				</figure>
				<?php } ?>				
			</div>

		</div>
	</section>

<!-- ---------------------------------------------------------- -->


<script>

	$(document).ready(function() {		
		$('section .content > div').hide();
		$('section .content .profile').show('fast');
	});

	$('section.nav li.profile').click(function() {
		$('section.nav li').removeClass('selected');
		$(this).addClass('selected');
		$('section .content > div').hide();
		$('section .content .profile').show('fast');
	});
	$('section.nav li.uploaded').click(function() {
		$('section.nav li').removeClass('selected');
		$(this).addClass('selected');
		$('section .content > div').hide();
		$('section .content .uploaded').show('fast');
	});
	$('section.nav li.reading').click(function() {
		$('section.nav li').removeClass('selected');
		$(this).addClass('selected');		
		$('section .content > div').hide();
		$('section .content .reading').show('fast');
	});
	$('section.nav li.tags').click(function() {
		$('section.nav li').removeClass('selected');
		$(this).addClass('selected');
		$('section .content > div').hide();
		$('section .content .tags').show('fast');
	});

	function removeReading(bookId) {
		var cf = confirm("Bạn có chắc không muốn theo dõi tài liệu này? ");
		if (cf == true ) {
			$.ajax({
				type: "POST",
				url: '/openlibraryonline/user/remove_reading/',
				data: ({
					book: bookId,
				}),
				success: function(data) {
					location.reload();
				},
				error: function() {
					alert('Kết nối thất bại');
				}
			});
		}
		return false;
	}
</script>

<?php
/** Load Footer
*/
$this->load->view('footer') ;
?>
